import React from "react";
import { useNavigate } from "react-router-dom";
export default function Home() {
  const navigate = useNavigate();

  return (
    <div>
      <h3>首页</h3>
          <button
            //通过编程式导航传递参数
        onClick={() => {
          navigate("/one?a=9&b=99");
        }}
      >
        ONE4
      </button>
      <button
        onClick={() => {
          navigate({
            pathname: "/one?a=99&b=999",
          });
        }}
      >
        ONE5
          </button>
          <button onClick={() => {
              navigate({
                  pathname: "/one",
                  search: 'a=999&b=9999'
              })
      }}>ONE6</button>
      

      {/* state 传值 任意类型都可,但开启新的进程,数据会清空 */}
      <button onClick={() => {
        navigate({ pathname: '/two' }, {
          state: {
            a: 1,
            b: 2,
            c: {
              userName:'zhangsan'
            }
          }
        });
      }}>
        TWO
      </button>
    </div>
  );
}
